/***************************************************************************
 *   Copyright (C) 2007 by Alexandre Masselot,,,   *
 *   alex@alex-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "utils/deltamassbuilder.h"

#include <iostream>

using namespace std;
using namespace bol;

void testDa();
void testPpm();

int main(int argc, char **argv){
  testDa();
  testPpm();
}

void testDa(){
  DeltaMassBuilder builder;
  DeltaMass* tol=builder.deltamassInstance("2Da");
  cout<< *tol<<endl;
  tol=builder.deltamassInstance(" 2.3Da");
  cout<< *tol<<endl;
  tol=builder.deltamassInstance(" .2 DA");
  cout<< *tol<<endl;
  tol=builder.deltamassInstance("2da  ");
  cout<< *tol<<endl;

  double m=1000;
  double mfar1=900;
  double mfar2=1010;
  double mclose1=1001;
  double mclose2=999;
  cout<<"should be far:"<<(tol->isInRange(m, mfar1)?"PROBLEM":"ok")<<"\n";
  cout<<"should be far:"<<(tol->isInRange(m, mfar2)?"PROBLEM":"ok")<<"\n";
  cout<<"should be close:"<<(tol->isInRange(m, mclose1)?"ok":"PROBLEM")<<"\n";
  cout<<"should be close:"<<(tol->isInRange(m, mclose2)?"ok":"PROBLEM")<<"\n";

  double inf, sup;
  tol->range(m, inf, sup);
  cout<<m<<" +/-"<< *tol<<" ["<<inf<<","<<sup<<"]"<<endl;
  cout<<"inf should be close:"<<(tol->isInRange(m, inf)?"ok":"PROBLEM")<<"\n";
  cout<<"sup should be close:"<<(tol->isInRange(m, sup)?"ok":"PROBLEM")<<"\n";
}

/**
 * 
 */
void testPpm(){
  DeltaMassBuilder builder;
  DeltaMass* tol=builder.deltamassInstance("1000ppm");
  cout<< *tol<<endl;
  tol=builder.deltamassInstance("1000.0ppm");
  cout<< *tol<<endl;

  double m=2000;
  double mfar1=1998;
  double mfar2=2005;
  double mclose1=1999;
  double mclose2=2002.0000001;
  cout<<"should be far:"<<(tol->isInRange(m, mfar1)?"PROBLEM":"ok")<<"\n";
  cout<<"should be far:"<<(tol->isInRange(m, mfar2)?"PROBLEM":"ok")<<"\n";
  cout<<"should be close:"<<(tol->isInRange(m, mclose1)?"ok":"PROBLEM")<<"\n";
  cout<<"should be close:"<<(tol->isInRange(m, mclose2)?"ok":"PROBLEM")<<"\n";

  double inf, sup;
  tol->range(m, inf, sup);
  int prec=cout.precision();
  cout.precision(10);
  cout<<m<<" +/-"<< *tol<<" ["<<inf<<","<<sup<<"]"<<endl;
  cout<<"inf should be close:"<<(tol->isInRange(m, inf)?"ok":"PROBLEM")<<"\n";
  cout<<"sup should be close:"<<(tol->isInRange(m, sup)?"ok":"PROBLEM")<<"\n";

  cout.precision(prec);
}
